unit perdidas;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Provider, SqlExpr, DB, DBClient, DBLocal, DBLocalS, Grids,
  DBGrids, RXDBCtrl, StdCtrls, Mask, ToolEdit, DateUtils, Buttons,
  ExtCtrls, DBCtrls;

type
  TfrmPerdidasVs = class(TForm)
    grdPerdida: TRxDBGrid;
    cdsPerdida: TSQLClientDataSet;
    sPerdida: TDataSource;
    cdsPerdidaID_PERDIDA: TIntegerField;
    cdsPerdidaCONCEPTO: TStringField;
    cdsPerdidaFECHA: TSQLTimeStampField;
    cdsPerdidaIMPORTE: TFloatField;
    lblFechaIni: TLabel;
    lblFechaFin: TLabel;
    DBNavigator1: TDBNavigator;
    btnGrabar: TBitBtn;
    edtFechaIni: TDateEdit;
    edtFechaFin: TDateEdit;
    cdsPerdidatotal: TAggregateField;
    DBText1: TDBText;
    Label1: TLabel;
    procedure cdsPerdidaNewRecord(DataSet: TDataSet);
    procedure sPerdidaStateChange(Sender: TObject);
    procedure btnGrabarClick(Sender: TObject);
    procedure edtFechaIniChange(Sender: TObject);
  private
    FidUsuario: integer;
    procedure SetidUsuario(const Value: integer);
    { Private declarations }
  published
    property idUsuario: integer read FidUsuario write SetidUsuario;
  public
    constructor CreateNuevo(AOwner: TComponent; usuario: word);
  end;

var
  frmPerdidasVs: TfrmPerdidasVs;

implementation

uses MDatos, Recursos;

{$R *.dfm}



{ TfrmPerdidasVs }

constructor TfrmPerdidasVs.CreateNuevo(AOwner: TComponent; usuario: word);
begin
  inherited Create(self.Owner);
  self.idUsuario := usuario;
  self.edtFechaIni.Date := IncMonth(now, -1);
  self.edtFechaFin.Date := now;
  self.ShowModal;
end;

procedure TfrmPerdidasVs.SetidUsuario(const Value: integer);
begin
  FidUsuario := Value;
end;

procedure TfrmPerdidasVs.cdsPerdidaNewRecord(DataSet: TDataSet);
begin
  self.cdsPerdidaID_PERDIDA.AsInteger := id('PERDIDA_GEN');
end;

procedure TfrmPerdidasVs.sPerdidaStateChange(Sender: TObject);
begin
  self.btnGrabar.Enabled := (self.cdsPerdida.ChangeCount > 0);
end;

procedure TfrmPerdidasVs.btnGrabarClick(Sender: TObject);
begin
  self.cdsPerdida.ApplyUpdates(0);
end;

procedure TfrmPerdidasVs.edtFechaIniChange(Sender: TObject);
begin
  self.cdsPerdida.Close;
  self.cdsPerdida.Params[0].AsString := FormatDateTime('mm/dd/yy', self.edtFechaIni.Date);
  self.cdsPerdida.Params[1].AsString := FormatDateTime('mm/dd/yy', self.edtFechaFin.Date);
  self.cdsPerdida.Open;
end;

end.
